package ${package}<#if moduleName??>.${moduleName}</#if>.convert<#if subModuleName??>.${subModuleName}</#if>;

import ${package}<#if moduleName??>.${moduleName}</#if>.entity<#if subModuleName??>.${subModuleName}</#if>.${ClassName}Entity;
import ${package}<#if moduleName??>.${moduleName}</#if>.vo<#if subModuleName??>.${subModuleName}</#if>.${ClassName}VO;
import ${package}<#if moduleName??>.${moduleName}</#if>.query<#if subModuleName??>.${subModuleName}</#if>.${ClassName}Query;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* ${tableComment}
*
* @author ${author} ${email}
* @since ${version} ${date}
*/
public class ${ClassName}Convert {

    public static IPage<${ClassName}Entity> getPage(${ClassName}Query query){
        Page<${ClassName}Entity> page = new Page<>(query.getPage(), query.getLimit());

        if(StringUtils.isNotBlank(query.getOrder())){
            if(query.isAsc()) {
                return page.addOrder(OrderItem.asc(query.getOrder()));
            }else {
                return page.addOrder(OrderItem.desc(query.getOrder()));
            }
        }
        return page;
    }

    public static ${ClassName}Entity convert(${ClassName}VO vo){
        ${ClassName}Entity entity = null;
        if (Objects.nonNull(vo)) {
            entity = new ${ClassName}Entity();
            BeanUtils.copyProperties(vo, entity);
        }
        return entity;
    }

    public static ${ClassName}VO convert(${ClassName}Entity entity){
        ${ClassName}VO vo = null;
        if (Objects.nonNull(entity)) {
            vo = new ${ClassName}VO();
            BeanUtils.copyProperties(entity, vo);
        }
        return vo;
    }

    public static List<${ClassName}VO> convertList(List<${ClassName}Entity> records){
        List<${ClassName}VO> list = new ArrayList<>(records.size());
        if (CollectionUtils.isNotEmpty(records)) {
            records.forEach(entity -> {
                ${ClassName}VO vo = new ${ClassName}VO();
                BeanUtils.copyProperties(entity, vo);
                list.add(vo);
            });
        }
        return list;
    }

}